package com.fanshuai.spring.boot.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.RedisNode;
import org.springframework.data.redis.connection.RedisSentinelConfiguration;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;

@Configuration
@ConditionalOnProperty({"redis.sentinel.enabled"})
public class RedisSentinelConfig {
    @Bean
    public RedisConnectionFactory connectionFactory() {
        RedisSentinelConfiguration configuration = new RedisSentinelConfiguration()
                .master("redis1")
                .sentinel(new RedisNode("localhost", 26379));

        return new LettuceConnectionFactory(configuration);
    }
}
